﻿#pragma once

#include <iostream>
#include <memory>

namespace Temp
{
	//抽象电脑类
	class Base_Computer
	{
	public:
		/****************最终指针**************** */
		using _ptr = std::shared_ptr<Base_Computer>;
		/****************构造析构**************** */
		Base_Computer() {}
		~Base_Computer() {}
		/****************成员函数**************** */
		std::string ToString()
		{
			std::string lo_computer = "Computer:{\n";
			lo_computer += "\thost->\t" + _host + "\n";
			lo_computer += "\tdisplay->\t" + _display + "\n";
			lo_computer += "\tos->\t" + _os + "\n";
			lo_computer += "}\n";
			return lo_computer;
		}
		/****************GetSet**************** */
		void SetHost(const std::string& host)
		{
			_host = host;
		}
		void SetDisplay(const std::string& display)
		{
			_display = display;
		}
		virtual void SetOs(const std::string& os) = 0;
	protected:
		std::string _host;		//主机
		std::string _display;	//显示器
		std::string _os;		//操作系统
	};

	//具体产品类
	class MacBook_Computer :public Base_Computer
	{
	public:
		/****************最终指针**************** */
		using _ptr = std::shared_ptr<MacBook_Computer>;
		/****************构造析构**************** */
		MacBook_Computer() {}
		~MacBook_Computer() {}
		/****************GetSet**************** */
		void SetOs(const std::string& os)override
		{
			_os = os;
		}
	};

	//抽象建造者类：包含创建⼀个产品对象的各个部件的抽象接⼝
	class Base_Builder
	{
	public:
		/****************最终指针**************** */
		using _ptr = std::shared_ptr<Base_Builder>;
		/****************构造析构**************** */
		Base_Builder() {}
		~Base_Builder() {}
		/****************GetSet**************** */
		virtual Base_Computer::_ptr GetComputer() = 0;
		/****************成员函数**************** */
		virtual void BuildHost(const std::string& host) = 0;
		virtual void BuildDisplay(const std::string& display) = 0;
		virtual void BuildOs(const std::string& os) = 0;
	};

	//具体产品的具体建造者类：实现抽象接⼝，构建和组装各个部件
	class MacBook_Builder :public Base_Builder
	{
	public:
		/****************最终指针**************** */
		using _ptr = std::shared_ptr<MacBook_Builder>;
		/****************构造析构**************** */
		MacBook_Builder() :_computer(std::make_shared<MacBook_Computer>()) {}
		~MacBook_Builder() {}
		/****************GetSet**************** */
		Base_Computer::_ptr GetComputer() override
		{
			return _computer;
		}
		/****************成员函数**************** */
		void BuildHost(const std::string& host)override
		{
			_computer->SetHost(host);
		}
		void BuildDisplay(const std::string& display)override
		{
			_computer->SetDisplay(display);
		}
		void BuildOs(const std::string& os)override
		{
			_computer->SetOs(os);
		}

	private:
		Base_Computer::_ptr _computer;
	};

	//指挥者类，提供给调⽤者使⽤，通过指挥者来构造复杂产品
	class Director
	{
	public:
		/****************构造析构**************** */
		Director(std::shared_ptr<Base_Builder> builder) :_builder(builder) {}
		~Director() {}
		/****************GetSet**************** */
		/****************成员函数**************** */
		void construct(const std::string& host, const std::string& display, const std::string& os)
		{
			_builder->BuildHost(host);
			_builder->BuildDisplay(display);
			_builder->BuildOs(os);
		}
	private:
		Base_Builder::_ptr _builder;
	};



}


